<template>
  <div class="user">
    <page-search :searchFormConfig="formConfig"
     @resetBtnClick="handleResetClick"
     @queryBtnClick="handleQueryClick"
     >
    </page-search>

    <page-content
    ref="pageContentRef"
    :contentTableConfig="contentTableConfig"
    pageName="users"
    @newBtnClick="handleNewData"
    @editBtnClick="handleEditData"
    ></page-content>

    <page-modal ref="pageModalRef" :modalConfig="modalConfigRef"
    :defaultInfo="defaultInfo" pageName="users"
    ></page-modal>
  </div>
</template>

<script lang="ts">
import { defineComponent , computed} from "vue";
import { useStore } from '@/store'
import { formConfig } from './config/search.config'
import { contentTableConfig } from './config/content.config'
import PageSearch from '@/components/page-search'
import PageContent from '@/components/page-content'

import { modalConfig } from './config/modal.config'
import PageModal from '@/components/page-modal'

import { usePageSearch } from '@/hooks/use-page-search'

// import HyTable from '@/base-ui/table'
import { Edit, Share, Delete, Search, Refresh } from '@element-plus/icons'

import { usePageModal } from '@/hooks/use-page-modal'


export default defineComponent({
  name:'user',
  components:{
    PageSearch,
    // HyTable,
    PageContent,
    // HyForm,
    PageModal,
  },
  setup() {

    //使用hooks
    const [pageContentRef,handleResetClick,handleQueryClick] = usePageSearch();

    //pageModal相关hooks
    const newCallBack = () => {
      const passwordItem = modalConfig.formItems.find(item => item.field === 'password')
      passwordItem!.isHidden = false
    };
    const editCallBack = () => {
       const passwordItem = modalConfig.formItems.find(item => item.field === 'password')
      passwordItem!.isHidden = true
    }

    //动态添加部门和角色列表
    const store = useStore()
    const modalConfigRef = computed(()=>{
      const departmentItem = modalConfig.formItems.find((item) => item.field === 'departmentId')

      departmentItem!.options = store.state.entireDepartment.map(item => {
        return {title:item.name,value:item.id}
      })
      const roleItem = modalConfig.formItems.find((item) => item.field === 'roleId')
      roleItem!.options = store.state.entireRole.map(item => {
        return {title:item.name,value:item.id}
      })
      // console.log(store.state.entireRole,1212121)
      return modalConfig
    })



    const [pageModalRef,defaultInfo,handleNewData,handleEditData] = usePageModal(newCallBack,editCallBack)

    return {
      formConfig,
      Edit,
      Delete,
      Refresh,
      contentTableConfig,
      handleResetClick,
      handleQueryClick,
      pageContentRef,
      modalConfig,
      handleNewData,
      handleEditData,
      pageModalRef,
      defaultInfo,
      modalConfigRef,
    }
  }
})
</script>

<style lang="less" scoped>
.user{
  .content{
    padding:15px;
  }
}
</style>
